package de.mhus.lib.mandala.impl;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;

import javax.servlet.ServletResponse;

import de.mhus.lib.core.base.IgnoreBind;
import de.mhus.lib.mandala.Response;
import de.mhus.lib.mandala.Ui;
import de.mhus.lib.mandala.Window;

@IgnoreBind
public class DefaultUi extends Ui {

	private HashSet<String> inlineTags = new HashSet<String>();
	
	public DefaultUi() {
		// TODO from configuration
		inlineTags.add("em");
		inlineTags.add("strong");
		inlineTags.add("small");
		inlineTags.add("span");
	}
	
	@Override
	public boolean isTextTag(String tagName) {
		return inlineTags.contains(tagName);
	}

	@Override
	public Response createResponse(Window forWindow, Object... hints) throws IOException {
		
		PrintWriter out = null;
		for (Object attribute : hints) {
			if (attribute instanceof javax.servlet.ServletResponse)
				out = ((ServletResponse) attribute).getWriter();
			else
			if (attribute instanceof PrintWriter)
				out = (PrintWriter) attribute;
		}

		DefaultResponse response = new DefaultResponse(forWindow, out);
		return response;
	}

}
